<template>
    <div id="myCard">
        <header class="header">认领名帖</header>
        <section class="receiveitems">
            <div class="receiveitem" v-for="(item,index) in cardLists" :class="{active:dataid==item.id}" :key="index" @click="choose(item.id)">
                <i><img :src="baseUrl.baseUrl+item.cclogo"></i>
                <p>{{item.cname}}</p>
            </div>
        </section>
        <footer @click="submit(dataid)">提交认领</footer>
    </div>
</template>

<script>

import {receiveCard,toReceive} from '../../../js/dataServe.js'
import {baseUrl} from '../../../config/env'
export default {
    data(){
        return {
            cardLists:[],
            baseUrl:{baseUrl},
            dataid:''
        }
    },
    components:{},
    created(){
        // this.$store.commit('changeShowit',{val:false})
    },
    mounted(){
        //认领名帖
        if(sessionStorage.sid){
            let self = this;
            let responseData = receiveCard();
            responseData.then((res)=>{
                                        // console.log(decodeURIComponent(res.msg))
                                        if(res.result == 1){
                                            let items = res.data.list;
                                            items.forEach( (item,key) => {
                                                if(!item.uid){
                                                    this.cardLists.push(item)
                                                }
                                            })
                                        }
                                    })
        }
    },
    methods:{
        choose(id){
            this.dataid = id;//控制背景的高亮状态
        },
        submit(id){
            if(!id){
                alert('请选择需要申请的名帖')
            }else if(sessionStorage.sid){
                let self = this;
                let responseData = toReceive(id);
                responseData.then((res)=>{
                                            // console.log(decodeURIComponent(res.msg))
                                            if(res.result == 1){
                                                alert('申请成功，请等待审核！')
                                            }
                                        })
            }
        }
    }
}
</script>

<style scoped >
#myCard {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
}
.header{
    width:100%;
    height:3rem;
    line-height:3rem;
    background:#eee;
    color:#333;
    font-size:1.2rem;
    position: fixed;
    top: 0;
    z-index:5;
}
.header i{ color: #333;}
.receiveitems{
    margin-top:3rem;
}
.receiveitem{
    display:flex;
    padding:0.5rem 1rem;
    border-bottom: 1px solid #dfdfdf;
}
.receiveitem i{
    width:4rem;
    height:4rem;
    display:block;
}
.receiveitem p{
    height:4rem;
    line-height:4rem;
    margin-left:1rem;
}
.receiveitem i img{
    width:100%;
    height:100%;
    border-radius:5rem;
}
footer{
    position: fixed;
    bottom: 0;
    width: 100%;
    color: #ffffff;
    height: 3rem;
    line-height: 3rem;
    background: #606266;
}
.active{
    background: rgba(0,0,0,0.3);
}
</style>
